package com.java.demo;

public class ShuffleCard {
    public static void main(String[] args) {
        start();
    }

    public static void start(){
        // 做牌
        String[] pocker = new String[54];

        // 牌的四种花色
        String[] colors = {"方块", "梅花", "黑桃", "红心"};
        String[] numbers = {"2", "3",  "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};

        int idx = 0;
        for (int i = 0; i < colors.length; i++) {
            for (int j = 0; j < numbers.length; j++) {
                pocker[idx ++] = colors[i] + numbers[j];
            }
        }

        pocker[idx ++] = "大王";
        pocker[idx] = "小王";

        for (int i = 0; i < pocker.length; i++) {
            System.out.print(pocker[i] + " ");
        }
        System.out.println();

        // 洗牌
        for(int i = 0; i < pocker.length; i++){
            int idx1 = (int) (Math.random() * pocker.length);
            int idx2 = (int) (Math.random() * pocker.length);

            String temp =  pocker[idx1];
            pocker[idx1] = pocker[idx2];
            pocker[idx2] = temp;
        }
        System.out.println("洗牌之后：");
        for (int i = 0; i < pocker.length; i++) {
            System.out.print(pocker[i] + " ");
        }
        System.out.println();

    }
}
